package com.uduemc.biso.module.basic.service.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.uduemc.biso.core.extities.center.AuthorizeModelAction;
import com.uduemc.biso.module.basic.service.mapper.AuthorizeModelActionMapper;
import com.uduemc.biso.module.basic.service.service.AuthorizeModelActionService;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

@Service
public class AuthorizeModelActionServiceImpl implements AuthorizeModelActionService {

	@Autowired
	private AuthorizeModelActionMapper authorizeModelActionMapper;

	@Override
	public AuthorizeModelAction insert(AuthorizeModelAction authorizeModelAction) {
		authorizeModelActionMapper.insert(authorizeModelAction);
		return findOne(authorizeModelAction.getId());
	}

	@Override
	public AuthorizeModelAction insertSelective(AuthorizeModelAction authorizeModelAction) {
		authorizeModelActionMapper.insertSelective(authorizeModelAction);
		return findOne(authorizeModelAction.getId());
	}

	@Override
	public AuthorizeModelAction updateById(AuthorizeModelAction authorizeModelAction) {
		authorizeModelActionMapper.updateByPrimaryKey(authorizeModelAction);
		return findOne(authorizeModelAction.getId());
	}

	@Override
	public AuthorizeModelAction updateByIdSelective(AuthorizeModelAction authorizeModelAction) {
		authorizeModelActionMapper.updateByPrimaryKeySelective(authorizeModelAction);
		return findOne(authorizeModelAction.getId());
	}

	@Override
	public AuthorizeModelAction findOne(long id) {
		return authorizeModelActionMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<AuthorizeModelAction> findAll() {
		Example example = new Example(AuthorizeModelAction.class);
		example.setOrderByClause("`model_id` DESC, `order_num` ASC, `id` ASC");
		return authorizeModelActionMapper.selectByExample(example);
	}

	@Override
	public int deleteById(long id) {
		int deleteByPrimaryKey = authorizeModelActionMapper.deleteByPrimaryKey(id);
		return deleteByPrimaryKey;
	}

	@Override
	public List<AuthorizeModelAction> findByModelId(long modelId) {
		Example example = new Example(AuthorizeModelAction.class);
		Criteria criteria = example.createCriteria();
		criteria.andEqualTo("modelId", modelId);
		example.setOrderByClause("`order_num` ASC, `id` ASC");
		return authorizeModelActionMapper.selectByExample(example);
	}

}
